<meta charset="UTF-8">
<style type = "text/css">
	.input-group{
		margin-top: 30px;
	}
	.erre{
		color: red;
		size: 14px;
	}
</style>

<div class="mcy_body">
	<div id="home">
			<ul class="breadcrumb">
					<li><span class="glyphicon glyphicon-home"></span>&emsp;当前位置：</li>
					<li class="active">修改密码</li>
				</ul>
		<div class="input-group col-md-5 col-md-offset-3">
			<span class="input-group-addon">请输入原密码：</span>
			<input type="password" id = "pwd" onchange="pwdupdata(this.value)" class="form-control">
		</div>
		<div class="col-md-4 col-md-offset-4">
			<lable class="erre" id = "erre_pwd"></lable>	
		</div>
		
		<div class="input-group col-md-5 col-md-offset-3">
			<span class="input-group-addon">请输入新密码：</span>
			<input type="password" id = "pwd1" onchange="fun_1(this.value)" class="form-control">
		</div>
		<div class="col-md-4 col-md-offset-4">
			<lable class="erre" id = "erre_pwd1"></lable>	
		</div>
		
		<div class="input-group col-md-5 col-md-offset-3">
			<span class="input-group-addon">请再次输入新密码：</span>
			<input type="password" id = "pwd2" onchange="fun_2(this.value)" class="form-control">
		</div>
		<div class="col-md-4 col-md-offset-4">
			<lable class="erre" id = "erre_pwd2"></lable>	
		</div>
		
		<div class="input-group col-md-1 col-md-offset-8" style="margin-top: 20px">
			<input type="button" class="btn btn-primary col-md-12" value="提交" onclick="changePwd1()">
		</div><br><br>
	</div>
</div>

<script type = "text/javascript">
	function pwdupdata(str){
		$.post('pwd', {password: str}, function(data){
			if(!data){
				$("#erre_pwd").html("原密码输入错误！");
			}else{
				$("#erre_pwd").html("");
			}
		});
	}
	
	function fun_1(str){
		if(str == "" || str == null){
			$("#erre_pwd1").html("请输入新密码！");
		}else{
			$("#erre_pwd1").html("");
		}
	}
	
	function fun_2(str){
		if(str == "" || str == null){
			$("#erre_pwd2").html("请再次输入新密码！");
		}else{
			$("#erre_pwd2").html("");
		}
	}
	
	function changePwd1(){
		var pwd = $("#pwd").val();
		var pwd1 = $("#pwd1").val();
		var pwd2 = $("#pwd2").val();
		if(pwd == "" || pwd == null){
			$("#erre_pwd").html("请输入原密码！");
		}else {
			$.post('pwd', {password: pwd}, function(data){
				if(!data){
					$("#erre_pwd").html("原密码输入错误！");
				}else{
					if(pwd1 == "" || pwd1 == null){
						$("#erre_pwd1").html("请输入新密码！");
					}else if(pwd2 == "" || pwd2 == null){
						$("#erre_pwd2").html("请再次输入新密码！");
					}else if(pwd1 != pwd2){
						$("#erre_pwd2").html("两次密码输入不一致！");
					}else{
						$.post('changePwd1', {password: pwd1}, function(data){
							if(!data){
								bootbox.alert("修改失败！");
							}else{
								bootbox.alert({
								    buttons: {
									   ok: {
										    label: '确定',
										    className: 'btn btn-primary'
									    }
								    },
								    message: '修改成功！',
								    callback: function() {
								    	window.location.href="logout";
								    },
								    title: "提示",
							    });
							}
						});
					}
				}
			});
		}
	}
</script>
